package com.hqyj.javaGraduation.hotel.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hqyj.javaGraduation.hotel.dao.HotelTableDao;
import com.hqyj.javaGraduation.hotel.pojo.HotelTable;
import com.hqyj.javaGraduation.hotel.pojo.UserTableInfo;
import com.hqyj.javaGraduation.hotel.service.HotelTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
public class HotelTableServiceImpl implements HotelTableService {

    @Autowired
    private HotelTableDao hotelTableDao;

    //查询所有的座位信息
    @Override
    public HashMap<String,Object> queryAllHotelTable(HotelTable hotelTable) {
        HashMap<String, Object> map = new HashMap<>();
        //第一步：创建分页对象 userInfo.getPage()表示当前页，userInfo.getRow()每页大小
        Page<HotelTable> hotelTablePage = new Page<>(hotelTable.getPage(),hotelTable.getRow());

        //创建查询条件对象
        QueryWrapper<HotelTable> queryWrapper = new QueryWrapper<>();
        //精确查询
        queryWrapper.eq(hotelTable.getTableId()!=0, //条件
                "table_id",  //列名
                hotelTable.getTableId());   //参数值

        // 第二步: 查询分页，获取分页数据集
        Page<HotelTable> pageList = hotelTableDao.selectPage(hotelTablePage,queryWrapper);

        //获取当前页的集合
        map.put("info",pageList.getRecords());
        //获取总条数
        map.put("total",pageList.getTotal());
        //获取总页数
        map.put("totalPage",pageList.getPages());
        return map;
    }

    @Override
    public String queryHotelTableByTableId(int tableId) {
        return hotelTableDao.queryHotelTableByTableId(tableId);
    }

    //新增座位
    @Override
    @Transactional
    public HashMap<String, Object> insertTable(HotelTable table) {
        HashMap<String, Object> map = new HashMap<>();
        table.setTableState("空闲");
        int i = hotelTableDao.insertTable(table);
        if(i>0){
            map.put("info","新增座位成功");
        }
        else {
            map.put("info","新增座位失败");
        }
        return map;
    }

    // 删除座位
    @Override
    @Transactional
    public HashMap<String, Object> deleteTableByTableId(int tableId) {
        HashMap<String, Object> map = new HashMap<>();
        int i =hotelTableDao.deleteTableByTableId(tableId);
        if(i>0){
            map.put("info","删除座位成功");
        }else {
            map.put("info","删除座位失败");
        }
        return map;
    }

    //修改座位状态
    @Override
    @Transactional
    public HashMap<String, Object> updateTable(HotelTable table) {
        HashMap<String, Object> map = new HashMap<>();
        int i =hotelTableDao.updateTable(table);
        if(i>0){
            map.put("info","修改座位状态成功");
        }else {
            map.put("info","修改座位状态失败");
        }
        return map;
    }

}
